package com.eastcom.collection.tools.rmi

import java.rmi.RemoteException
import java.rmi.server.UnicastRemoteObject
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue
import java.io.ByteArrayInputStream;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.eastcom.collection.config.FtpTaskConfig;
import com.eastcom.collection.provider.PropertyPlaceholderConfigurerProvider;
import com.eastcom.collection.provider.SpringContextProvider;
import com.eastcom.collection.tools.file.JaxbUtil;
import com.eastcom.collection.tools.rmi.ift.ITaskSender;
@Component("taskSender")
@Scope("prototype")
class TaskSender extends UnicastRemoteObject implements ITaskSender{
	private static Log logger = LogFactory.getLog(TaskSender.class);
	@Override
	public Object send(String tasks)  throws RemoteException{
		// TODO 自动生成的方法存根
		ConcurrentLinkedQueue ftpTaskQueue = SpringContextProvider.getBean("ftpTaskReciveQueue")
		logger.debug("add a new ftp task["+tasks+"]")
		FtpTaskConfig ftpTask = JaxbUtil.converyStringToJavaBean(tasks, "UTF-8", FtpTaskConfig.class)
		ftpTaskQueue.add(ftpTask)
		return "ok";
	}
	@Override
	public List<String> getDataCatalog() throws RemoteException {
		// TODO 自动生成的方法存根
		String dataCatalog = PropertyPlaceholderConfigurerProvider.getContextProperty("DataCatalog")
		String[] dataCatalogList = dataCatalog.split("\\s*,\\s*")
		List<String> result = new ArrayList<String>()
		dataCatalogList.each {
			result.add(it)
		}
		return result;
	}
}
